package client;

import javax.swing.JFrame;
import javax.swing.JPanel;

import java.awt.BorderLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.BoxLayout;
import javax.swing.JLabel;

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.border.EmptyBorder;
import javax.swing.SwingConstants;

public class MainClient extends JFrame{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 410215280026718829L;

	public MainClient() {
		
		JPanel mainPanel = new JPanel();
		getContentPane().add(mainPanel, BorderLayout.CENTER);
		mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.X_AXIS));
		
		JPanel personalMessagePanel = new JPanel();
		personalMessagePanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		mainPanel.add(personalMessagePanel);
		personalMessagePanel.setLayout(new BorderLayout(0, 0));
		
		JPanel imagePanel = new JPanel();
		personalMessagePanel.add(imagePanel);
		
		JLabel label = new JLabel("");
		imagePanel.add(label);
		
		JPanel textPanel = new JPanel();
		personalMessagePanel.add(textPanel, BorderLayout.SOUTH);
		textPanel.setLayout(new GridLayout(2, 0, 0, 0));
		
		JLabel lblStudentId = new JLabel("201231000826");
		lblStudentId.setHorizontalAlignment(SwingConstants.CENTER);
		textPanel.add(lblStudentId);
		
		JLabel lblStudentName = new JLabel("全程");
		lblStudentName.setHorizontalAlignment(SwingConstants.CENTER);
		textPanel.add(lblStudentName);
		
		JLabel lblImage = new JLabel("");
		lblImage.setIcon(new ImageIcon(".\\image\\me.jpg"));
		imagePanel.add(lblImage);
		
		JPanel btnPanel = new JPanel();
		btnPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
		mainPanel.add(btnPanel);
		btnPanel.setLayout(new GridLayout(12, 0, 0, 0));
		
		JButton btn1Interface = new JButton("实验一：接口编程");
		btn1Interface.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				InterfaceProgrammingClient.main(null);
				
			}
		});
		btnPanel.add(btn1Interface);
		
		JButton btn2Singleton = new JButton("实验二：单例模式");
		btn2Singleton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SingletonClient.main(null);
				
			}
		});
		btnPanel.add(btn2Singleton);
		
		JButton btn3SingleFantory = new JButton("实验三：简单工厂模式");
		btn3SingleFantory.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SimpleFactoryMethodClient.main(null);
				
			}
		});
		btnPanel.add(btn3SingleFantory);
		
		JButton btn3Factory = new JButton("实验三：工厂模式");
		btn3Factory.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				FactoryMethodClient.main(null);
				
			}
		});
		btnPanel.add(btn3Factory);
		
		JButton btn3AbstractFactory = new JButton("实验三：抽象工厂模式");
		btn3AbstractFactory.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				AbstractFactoryMethodClient.main(null);
				
			}
		});
		btnPanel.add(btn3AbstractFactory);
		
		JButton btn4ObjectAdapter = new JButton("实验四：对象适配器模式");
		btn4ObjectAdapter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ObjectAdapterClient.main(null);
				
			}
		});
		btnPanel.add(btn4ObjectAdapter);
		
		JButton btn4ClassAdapter = new JButton("实验四：类适配器模式");
		btn4ClassAdapter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ClassAdapterClient.main(null);
				
			}
		});
		btnPanel.add(btn4ClassAdapter);
		
		JButton btn4MouseAdapter = new JButton("实验四：鼠标监听器适配器");
		btn4MouseAdapter.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				MouseAdatperClient.main(null);
				
			}
		});
		btnPanel.add(btn4MouseAdapter);
		
		JButton btn5CompositePattern = new JButton("实验五：组合模式");
		btn5CompositePattern.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				CompositePatternClient.main(null);
				
			}
		});
		btnPanel.add(btn5CompositePattern);
		
		JButton btn6HibernateORM = new JButton("实验六：Hibernate的ORM模式");
		btn6HibernateORM.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				HibernateClient.main(null);
				
			}
		});
		btnPanel.add(btn6HibernateORM);
		
		JButton btn7SpringDI = new JButton("实验七：Spring的DI模式");
		btn7SpringDI.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				SpringClient.main(null);
				
			}
		});
		btnPanel.add(btn7SpringDI);
		this.setBounds(100, 100, 550, 450);
		
		this.addWindowListener(new WindowAdapter(){
			public void windowClosing(WindowEvent arg0) {
			
			 System.exit(0);
			 }
		});
	}

	public static void main(String[] args) {
		new MainClient().setVisible(true);
		
	}
	
}
